#include <vector>
#include <utility>
#include <algorithm>
#include <iostream>
#include <numeric>

using namespace std;

int position(const vector<int> &arr, int n) {
  for (int i = 0; i < arr.size(); ++i) {
    if (arr[i] == n) {
      return i;
    }
  }

  return -1;
}

int solution(const vector<int> &cowA, const vector<int> &cowB) {
  vector<int> steps(cowA.size(), 0);

  for (int i = 0; i < cowA.size(); ++i) {
    for (int j = i + 1; j < cowA.size(); ++j) {
      if (position(cowB, cowA[i]) > position(cowB, cowA[j])) {
        steps[j] = 1;
      }
    }
  }

  return accumulate(steps.begin(), steps.end(), 0);
}

int main(int argc, char const *argv[])
{
  int cows = 0;
  cin >> cows;

  vector<int> cowA(cows, 0);
  for (int i = 0; i < cows; ++i) {
    cin >> cowA[i];
  }

  vector<int> cowB(cows, 0);
  for (int i = 0; i < cows; ++i) {
    cin >> cowB[i];
  }

  cout << solution(cowA, cowB) << endl;
  return 0;
}
